package main

import (
	"fmt"
	"time"
)

func findbound() {
	var c [500]int
	var maxx [500]int
	startTime := time.Now().UnixNano()

	for imm := 0; imm < 500; imm++ {
		A := RandGraph(50, 50)
		n := len(A)
		for i := 0; i < n-1; i++ {
			for j := i + 1; j < n; j++ {
				A[j][i] = A[i][j]
			}
		}
		d := CalculateD(A)
		max, _ := Max(d)

		min := 0

		for i := min + 1; i <= max+1; i++ {

			f, q := ChaitinSimply(A, i)
			if f {
				node := ChaitinSelect(A, q, i)
				c[imm] = i
				for i := 0; i < len(node); i++ {
					if maxx[imm] < node[i] {
						maxx[imm] = node[i]
					}
				}
				break
			} else {

			}
		}
	}
	endTime := time.Now().UnixNano()
	Milliseconds := float64((endTime - startTime) / 1e6)
	fmt.Println(maxx)
	fmt.Println(c)
	fmt.Println(Milliseconds)
}

func ctime() {
	var Milliseconds [100]float64
	for in := 5; in < 105; in++ {
		A := RandGraph(in, 50)
		n := len(A)
		startTime := time.Now().UnixNano()
		for imm := 0; imm < 1000; imm++ {

			for i := 0; i < n-1; i++ {
				for j := i + 1; j < n; j++ {
					A[j][i] = A[i][j]
				}
			}
			d := CalculateD(A)
			max, _ := Max(d)

			min := 0

			for i := min + 1; i <= max+1; i++ {

				f, q := ChaitinSimply(A, i)
				if f {
					node := ChaitinSelect(A, q, i)

					for i := 0; i < len(node); i++ {

					}
					break
				} else {

				}
			}
		}
		endTime := time.Now().UnixNano()
		Milliseconds[in-5] = float64((endTime - startTime) / 1e6)

	}
	fmt.Println(Milliseconds)

}

func testspillchaitin() {
	var a []int
	for i := 0; i < 50; i++ {
		A := RandGraph(50, 50)
		n := len(A)
		for i := 0; i < n-1; i++ {
			for j := i + 1; j < n; j++ {
				A[j][i] = A[i][j]
			}
		}
		a = append(a, Chaitin2(A, 0))

	}
	fmt.Println(a)
}

func testspillbriggs() {
	var a []int
	var b [50]int
	var c [50]int
	for in := 0; in < 50; in++ {
		A := RandGraph(50, 50)
		n := len(A)
		for i := 0; i < n-1; i++ {
			for j := i + 1; j < n; j++ {
				A[j][i] = A[i][j]
			}
		}
		for i := 2; i <= 50; i++ {

			f, q := ChaitinSimply(A, i)
			if f {
				node := ChaitinSelect(A, q, i)
				b[in] = i
				for i := 0; i < len(node); i++ {
					if c[in] < node[i] {
						c[in] = node[i]
					}
				}
				break
			} else {

			}
		}
		q := BriggsSimply(A)
		_, s := BriggsSelect(A, q, 12)
		a = append(a, s)
	}
	fmt.Println("briggs溢出(相对于8)", a)
	fmt.Println("Chaitin计算", b)
	fmt.Println("Chaitin使用", c)
}
